package com.chenc.javathreads.controlleraop.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chenc.javathreads.controlleraop.dao.OperateApiLogDao;
import com.chenc.javathreads.controlleraop.dto.OperateApiLogDto;
import com.chenc.javathreads.controlleraop.entity.OperateApiLog;
import com.chenc.javathreads.controlleraop.service.IOperateApiLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
*
* @description 接口日志接收记录表 服务实现类
* @author  chenc
* @since 2023-12-21 18:02:16
*/
@Service
public class OperateApiLogServiceImpl extends ServiceImpl<OperateApiLogDao, OperateApiLog> implements IOperateApiLogService {

    @Autowired
    OperateApiLogDao operateApiLogDao;


    @Override
    @Transactional
    public void saveEntity(OperateApiLogDto dto) {
        OperateApiLog convert = Convert.convert(OperateApiLog.class, dto);
        operateApiLogDao.insert(convert);
        return;
    }

    @Override
    public List<OperateApiLogDto> getlastTimes(String times) {
        List<OperateApiLog> operateApiLogs = operateApiLogDao.selectList(new LambdaQueryWrapper<OperateApiLog>()
                .orderByDesc(OperateApiLog::getId)
                .last("limit "+times));


        return Convert.toList(OperateApiLogDto.class,operateApiLogs);
    }

}
